from pywinauto import Application
import time
import pyautogui  # 用于截图

# 定义一个函数来打开第一个网址并截图
def open_first_url_and_screenshot():
    url = "https://dcs.cscec.com/"
    screenshot_path = "screenshot_1.png"
    
    app = Application().start(r'"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" ' + url)
    time.sleep(2)  # 等待页面加载

    edge_window = app.window(title_re=".*Edge.*")
    time.sleep(1)  # 等待 2 秒，确保窗口完全加载

    # 直接进行截图
    pyautogui.screenshot(screenshot_path)  # 截图
    print(f"{url} 已截图。")

    edge_window.close()

# 定义一个函数来打开第二个网址并截图
def open_second_url_and_screenshot():
    url = "https://cloudbases-manage.cscec.com/dc-prd-241106/clusters/dc-pro-kylin-20240515/projects/dc-udp-prd-ns/overview"
    screenshot_path = "screenshot_2.png"
    
    app = Application().start(r'"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" ' + url)
    time.sleep(2)  # 等待页面加载

    edge_window = app.window(title_re=".*Edge.*")
    time.sleep(2)  # 等待 2 秒，确保窗口完全加载

    # 直接进行截图
    pyautogui.screenshot(screenshot_path)  # 截图
    print(f"{url} 已截图。")

    edge_window.close()

# 定义一个函数来打开第三个网址并截图
def open_third_url_and_screenshot():
    url = "https://cloudbases-manage.cscec.com/clusters/dc-pro-kylin-20240515/nodes"
    screenshot_path = "screenshot_3.png"
    
    app = Application().start(r'"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" ' + url)
    time.sleep(2)  # 等待页面加载

    edge_window = app.window(title_re=".*Edge.*")
    time.sleep(2)  # 等待 2 秒，确保窗口完全加载

    # 直接进行截图
    pyautogui.screenshot(screenshot_path)  # 截图
    print(f"{url} 已截图。")

    edge_window.close()

# 调用函数以打开网址并截图
open_first_url_and_screenshot()
open_second_url_and_screenshot()
open_third_url_and_screenshot()